﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using LogicAndDB;
namespace WebHost
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

            Application.Add(CGlobalContext.APP_DATA_KEY, new CGlobalContext());
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            Logger.Write("new session:[" + Request.RawUrl + "]:");
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
      
            String content = Common.Util.returnResponsebody(Request.InputStream);
            Request.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
            Logger.Write("Request:["+Request.RawUrl+"]:"+content);
        }

        protected void Application_EndRequest(object sender, EventArgs e)
        {
            DBContainer.RemoveContext();
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            CGlobalContext context = Application[CGlobalContext.APP_DATA_KEY] as CGlobalContext;
            if (context != null)
                context.OnSessionEnd(Session);
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}